//=============================================================================
//
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//
//  Copyright 2015 Sandia Corporation.
//  Copyright 2015 UT-Battelle, LLC.
//  Copyright 2015 Los Alamos National Security.
//
//  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
//  the U.S. Government retains certain rights in this software.
//  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
//  Laboratory (LANL), the U.S. Government retains certain rights in
//  this software.
//
//=============================================================================
#include <cuda.h>
#include <cuda_runtime.h>
#include <iostream>


static
__global__
void DetermineIfValidCudaDevice()
{
}

struct PACKED_DEFINE result_type
{
  bool valid;
  std::string msg;
};

result_type can_launch_kernel()
{
  result_type r;
  DetermineIfValidCudaDevice <<<1,1>>> ();
  r.valid = (cudaSuccess == cudaGetLastError());
  if(r.valid)
    {
    r.msg = "ran a cuda kernel";
    }
  else
    {
    r.msg = "cant run a cuda kernel";
    }
  return r;
}

int main(int argc, char **argv)
{
  cudaError_t err;
  int nDevices = 0;
  err = cudaGetDeviceCount(&nDevices);
  if(err != cudaSuccess)
    {
      return 1;
    }
  std::cout << "this executable uses cuda code" << std::endl;
  std::cout << "you have " << nDevices << " devices that support cuda" << std::endl;
  std::cout << can_launch_kernel().msg << std::endl;
  return 0;
}
